
$(function () {
//拖拽上传
    layui.use(['element', 'layer', 'form', 'jquery', 'layedit'], function () {
        var $ = layui.jquery
            , element = layui.element
            , layer = layui.layer
            , form = layui.form
            , layedit = layui.layedit;
            layedit.set({
            //暴露layupload参数设置接口 --详细查看layupload参数说明
            uploadImage: {
                url: ipAddress()+'/image/uploadlayedit',
                accept: 'image',
                acceptMime: 'image/*',
                exts: 'jpg|png|gif|bmp|jpeg|gif|jfif',
                size: 1024 * 10,
                data: {
                    name: '测试参数',
                    age: 99,
                },
                done: function (data) {
                    console.log(data)
                },
            },
            //测试参数
            backDelImg: true,
            //开发者模式 --默认为false
            devmode: true,
            //是否自动同步到textarea
            autoSync: true,
            //内容改变监听事件
            onchange: function (content) {
                console.log(content)
            },
            //插入代码设置 --hide:false 等同于不配置codeConfig
            codeConfig: {
                hide: true, //是否隐藏编码语言选择框
                default: 'javascript', //hide为true时的默认语言格式
                encode: true, //是否转义
                class: 'layui-code', //默认样式
            },
            //新增iframe外置样式和js
            quote: {
                style: ['Content/css.css'],
            },
            //插入自定义链接
            customlink: {
                title: '插入layui官网',
                href: 'https://www.layui.com',
                onmouseup: '',
            },
            facePath: 'http://knifez.gitee.io/kz.layedit/Content/Layui-KnifeZ/',
            devmode: true,
            videoAttr: ' preload="none" ',
            tool: ['html','undo','redo','code', 'strong', 'italic','underline','del', 'addhr','|','removeformat','fontFomatt',
                'fontfamily','fontSize','lineHeight','fontBackColor','colorpicker','face','|','left','center','right',
                '|','link','unlink','images','image_alt','video','attachment','anchors', '|','table', 'customlink','fullScreen',
                'preview',
            ],
            height: '200px',
        })

        let index = layedit.build('layeditDemo'); //建立编辑器

        let res = myAjax("/company/g", {}, "get");
        setContent(res);
        //监听提交
        form.on('submit(add)',
            function (data) {

                data = data.field;
                data.content=layedit.getContent(index);
                let res=myAjax(ipAddress()+'/company/u',data,'put');
                if(res.count==1) {
                    //发异步，把数据提交给php
                    layer.alert("增加成功", {
                            icon: 6
                        },
                        function () {
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                    return false;
                }else{
                    layer.alert('上传失败',{icon:5})
                }
            });

        function setContent(data) {
            layedit.setContent(index, res.data.content);
        }
    });


})